<%
Dim NameRecordSet ' - [rs] / [objRecordset]
Dim PCnt ' - Count page on string
Dim PageNow ' - Page [Request.QueryString("page")]
Dim NameAddrPage ' - [page] / [nom]
Dim StringAddress ' - ["AutomatSpisok.asp?sort="&sSort&""]
Dim NameClass ' - ["class='PageLink'"]
Dim NameHeading ' - Name Heading  [Zagolovok]
Dim NamePrev
Dim NameNext

FUNCTION StringPage(NameRecordSet,PCnt,PageNow,NameAddrPage,StringAddress,NameClass,NameHeading,NamePrev,NameNext)
	Dim ModPCnt, FirstP, LastP, aPrev, aNext, strA, q

if Request.QueryString(NameAddrPage) <> empty then
	if Request.QueryString(NameAddrPage)<1 then
		PageNow=1
		NameRecordSet.absolutepage=1
	else
		PageNow=Request.QueryString(NameAddrPage)
		NameRecordSet.absolutepage=Request.QueryString(NameAddrPage)
	end if
else
	PageNow=1
	NameRecordSet.absolutepage=1
end if

ModPCnt=(NameRecordSet.pagecount mod cint(PCnt))
if NameRecordSet.pagecount>cint(PCnt) then
	if cint(PageNow)>NameRecordSet.pagecount then
		PageNow=NameRecordSet.pagecount
		NameRecordSet.absolutepage=clng(PageNow)
		FirstP=cint(NameRecordSet.pagecount)-cint(PCnt)
		LastP=NameRecordSet.pagecount
		aPrev="<a href='"&StringAddress&"&"&NameAddrPage&"=1' "&NameClass&">1 </a>&nbsp;<a href='"&StringAddress&"&"&NameAddrPage&"="&NameRecordSet.pagecount-cint(ModPCnt)&"' "&NameClass&">"&NamePrev&"</a>"
		aNext=""
	else
		if cint(PageNow)<1 then
			PageNow=1
			FirstP=1
			LastP=cint(PCnt)
			NameRecordSet.absolutepage=cint(FirstP)
			aPrev=""
			aNext="&nbsp;<a href='"&StringAddress&"&"&NameAddrPage&"="&(LastP)&"' "&NameClass&">"&NameNext&"</a>&nbsp;<a href='"&StringAddress&"&"&NameAddrPage&"="&NameRecordSet.pagecount&"' "&NameClass&">"&NameRecordSet.pagecount&"</a>"					
		else
			if cint(PageNow)=>(cint(NameRecordSet.pagecount)-cint(ModPCnt)) then
				FirstP=(cint(NameRecordSet.pagecount)-cint(ModPCnt))
				LastP=cint(NameRecordSet.pagecount)
				aPrev="<a href='"&StringAddress&"&"&NameAddrPage&"=1' "&NameClass&">1 </a>&nbsp;<a href='"&StringAddress&"&"&NameAddrPage&"="&(cint(FirstP)-cint(PCnt)+1)&"' "&NameClass&">"&NamePrev&"</a>"
				aNext=""
			else
				FirstP=(cint(PageNow)-(cint(PageNow) mod cint(PCnt)))
				LastP=FirstP+cint(PCnt)
				aPrev="<a href='"&StringAddress&"&"&NameAddrPage&"=1' "&NameClass&">1 </a>&nbsp;<a href='"&StringAddress&"&"&NameAddrPage&"="&(cint(FirstP)-cint(PCnt))&"' "&NameClass&">"&NamePrev&"</a>"	
				aNext="&nbsp;<a href='"&StringAddress&"&"&NameAddrPage&"="&(LastP)&"' "&NameClass&">"&NameNext&"</a>&nbsp;<a href='"&StringAddress&"&"&NameAddrPage&"="&NameRecordSet.pagecount&"' "&NameClass&">"&NameRecordSet.pagecount&"</a>"
				if 	FirstP<1 then
					FirstP=1
					LastP=cint(PCnt)
					aPrev=""	
					aNext="&nbsp;<a href='"&StringAddress&"&"&NameAddrPage&"="&(LastP)&"' "&NameClass&">"&NameNext&"</a>&nbsp;<a href='"&StringAddress&"&"&NameAddrPage&"="&NameRecordSet.pagecount&"' "&NameClass&">"&NameRecordSet.pagecount&"</a>"
				end if		
				if LastP=>cint(NameRecordSet.pagecount) then
					FirstP=(cint(NameRecordSet.pagecount)-cint(ModPCnt))
					LastP=cint(NameRecordSet.pagecount)
					PageNow=NameRecordSet.pagecount
					NameRecordSet.absolutepage=clng(PageNow)
					aPrev="<a href='"&StringAddress&"&"&NameAddrPage&"=1' "&NameClass&">1</a>&nbsp;<a href='"&StringAddress&"&"&NameAddrPage&"="&(cint(FirstP)-cint(PCnt))&"' "&NameClass&">"&NamePrev&"</a>"
					aNext=""
				end if
			end if
		end if
	end if
else
	FirstP=1
	LastP=NameRecordSet.pagecount
	aPrev="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
	aNext=""
end if
		strA=""
		q=FirstP
	  for q=FirstP to LastP
	  	if q<>cint(PageNow) then
			strA=strA&"&nbsp;<a href='"&StringAddress&"&"&NameAddrPage&"="&q&"' "&NameClass&">"&q&"</a>"		 		
		else
			strA=strA&"&nbsp;<font color=red>["&q&"]</Font>"
		end if
	  Next
	  
	if NameRecordSet.pagecount<=1 then
		StringPage=""
	else 
		StringPage=NameHeading&aPrev&strA&aNext
	end if
	
END FUNCTION
%>
